#!/bin/sh

if [ $# -ne 0 ]; then
	echo "Simple packaging file for the source."
	echo ""
	echo "Use in the root directory of the game, like so:"
	echo "   scripts/pkg_src"
	echo "The script will output a tarball angband_[git describe].orig.tar.gz"

	exit 1
fi

TAG1=angband-`git describe`
TAG2=angband_`git describe`
OUT=$TAG2.orig.tar.gz

# Error checking
if [ -e $OUT ]; then
	cat <<EOF
The output file $OUT already exists.
Please rename or delete it before running the script again.
EOF
	exit 1
fi

if [ -e $TAG1 ]; then
	cat <<EOF
The output directory $TAG1 already exists.
Please rename or delete it before running the script again.
EOF
	exit 1
fi

git checkout-index --prefix=$TAG1/ -a &&
	git describe > $TAG1/version &&
	cd $TAG1 &&
	./autogen.sh &&
	rm -rf autogen.sh autom4te.cache &&
	cd .. &&
	tar --exclude .gitignore --exclude *.dll --exclude *.wav -czvf $OUT $TAG1 &&
	rm -rf $TAG1
